package com.gf.controller.order;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gf.bean.Orderr;
import com.gf.service.impl.OrderrServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

/*
 * 这是当用户点击送达按钮时候给订单添加订单结束时间也就是让订单完成的servlet （当订单的结束时间字段（endtime）有对应的日期时就标志着订单完成）
 * */

@WebServlet(name = "AddorderendtimeServlet",urlPatterns = "/addorderendtime")
public class AddendtimeServlet extends HttpServlet {
    static OrderrServiceImpl orderimpl = null;
    static {
        orderimpl=new OrderrServiceImpl();


    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        Orderr orderr = new Orderr();
        //创建对应的订单对象用来传递数据
        String order_id = request.getParameter("order_id");
        //接收传递过来的order_id
        orderr.setOrder_id(order_id);
        //给orderr对象设置订单编号
        orderr.setEnd_time(new Date());
        //给订单对象设置结束日期
        orderimpl.setorderendtime(orderr);
        //再将填充好数据的order对象传递过去让mybatis可以通过orderid设置对应的结束时间
        JSONObject backjson = new JSONObject();
        //新建json对象，设置成功的响应码,将对应的数据插入然后返回
        backjson.put("status", 200);
        backjson.put("data", "送达成功");

        out.println(JSON.toJSON(backjson));
        out.flush();
        out.close();

    }
}
